package com.jxpanda.spring.module.auth.core.user;

import lombok.Getter;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.oauth2.core.user.OAuth2User;

import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Getter
public abstract class AbstractOAuth2User implements OAuth2User {


    public static final String USER_ID_ATTRIBUTE_NAME = "oauth2UserIdAttributeName";

    protected String userIdAttributeName;

    protected final Map<String, Object> attributes;

    public AbstractOAuth2User(String userIdAttributeName) {
        this.userIdAttributeName = userIdAttributeName;
        this.attributes = new HashMap<>(8);
        this.attributes.put(USER_ID_ATTRIBUTE_NAME, userIdAttributeName);
    }

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return List.of();
    }

    @Override
    public String getName() {
        return getAttributes()
                .get(this.getUserIdAttributeName())
                .toString();
    }

}
